from __future__ import unicode_literals
from django.db import models
from optitrans.domain.modelhelper import PositionManager
from optitrans.domain.position import Position
from optitrans.domain.chauffeur import Chauffeur

class PositionManager(models.Manager):
   
       
    def position(self, id):
        return  Position.objects.order_by('-id').get(id_vehicule=id)
     
        

class Vehicule(models.Model):
    id = models.IntegerField(primary_key=True)
    id_client = models.IntegerField()
    immatricule = models.CharField(max_length=50L)
    nom = models.CharField(max_length=250L, blank=True)
    marque = models.CharField(max_length=250L, blank=True)
    objects = models.Manager()
    positions=PositionManager()
   
        
    class Meta:
        db_table = 'vehicule'
        
    
    def get_status(self):
        return Vehicule.positions.position(self.id).status

    def get_matricule(self):
        return self.immatricule

    def get_distance(self):
        return Vehicule.positions.position(self.id).distanfromBamako()
         
    def get_chauffeur(self):
        return Vehicule.positions.position(self.id).id_chauffeur
    
    def get_vitesse(self):
        return Vehicule.positions.position(self.id).vitesse
    def get_latitude(self):
      
        return 'self.objects.latitude'
    def get_longitude(self):
       
        return 'self.objects.longitude'



